package com.jh.paymentchannel.util.yipiaolian;

import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Properties;

public class Parameters
{
  private static Properties properties = null;

  static { if (properties == null) {
      InputStreamReader inputStream = null;
      try {
        properties = new Properties();
        ClassLoader cl = Thread.currentThread().getContextClassLoader();

        if (cl != null) {
          inputStream = new InputStreamReader(cl
            .getResourceAsStream("paycenter_config.properties"), "UTF-8");
        }
        if (inputStream != null) {
          properties.load(inputStream);
          inputStream.close();
        }
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    Enumeration enumeration = properties.keys();
    while (enumeration.hasMoreElements()) {
      String key = enumeration.nextElement().toString();
      String value = properties.getProperty(key);
      properties.setProperty(key, wipeOffQuotation(value));
    }
  }

  public static String getProperty(String key)
  {
    return properties.getProperty(key);
  }

  private static String wipeOffQuotation(String value)
  {
    if ((value != null) && (value.length() > 0) && 
      (value.indexOf("\"") == 0) && 
      (value.lastIndexOf("\"") == value.length() - 1)) {
      return value.substring(1, value.length() - 1);
    }
    return value;
  }

  public static String[] getPropertys(String key)
  {
    String str = properties.getProperty(key);
    return str.split(";");
  }
}
